package weifei.live.simulation.im.entity;


import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.stereotype.Repository;
import weifei.live.simulation.im.cmd.Message;


@Data
@EqualsAndHashCode(callSuper = true)
@TableName("user_friend_message_cache")
@Repository
public class UserFriendMessageCache extends Model<UserFriendMessageCache>
{
    @Getter
    public enum Column
    {
        ID("id"),
        Type("type"),
        Format("format"),
        SenderID("sender_id"),
        ReceiverID("receiver_id"),
        Content("content"),
        SendTime("send_time"),
        CacheTime("cache_time");

        final String name;

        Column(String name) { this.name = name; }
    }

    @TableId
    private Integer id;
    private Message.Type type;
    private Message.Format format;
    private Integer senderId;
    private Integer receiverId;
    private String content;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private java.util.Date sendTime;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private java.util.Date cacheTime;


    /** 做数据库修改用 */
    public UserFriendMessageCache() {}

    public UserFriendMessageCache(
            Message.Type type,
            Message.Format format,
            Integer senderId,
            Integer receiverId,
            String content,
            java.util.Date sendTime
        )
    {
        this.type = type;
        this.format = format;
        this.senderId = senderId;
        this.receiverId = receiverId;
        this.content = content;
        this.sendTime = sendTime;
    }


    public Message toMessage()
    {
        return new Message(
            this.type,
            this.format,
            Message.Destination.UserToFriend,
            this.senderId,
            new Integer[]{this.receiverId},
            this.content,
            this.sendTime
        );
    }
}



